import {setdebounce} from '@/js/myloadsh.js'

/**
 * 回到顶部的显示
 */
var backtop = $('.backtop');
function backtopFunc(event) {
    let h = document.documentElement.scrollTop || document.body.scrollTop;
    console.log('h:',h);
    if(h > 768) {
        if(backtop.hasClass('deactive')) {
            backtop.removeClass('deactive').addClass('active');
        }
    } else {
        if(backtop.hasClass('active')) {
            backtop.removeClass('active').addClass('deactive');
        }
    }
}
var bebounce = setdebounce(backtopFunc,100);
window.addEventListener('scroll',bebounce);


/**
 * 回到顶部动画
 */
backtop.on('click',function() {
    gotop();
})
function gotop() {
    (function smoothscroll() {
        var currentScroll = document.documentElement.scrollTop || document.body.scrollTop;
        if (currentScroll > 0) {
            window.requestAnimationFrame(smoothscroll);
            window.scrollTo(0, currentScroll - (currentScroll / 5));
        }
    })()
}